package com.ruoyi.project.module.productsUpload.controller;

import java.util.List;

import com.ruoyi.common.utils.UserUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.constant.BusinessType;
import com.ruoyi.project.module.productsUpload.domain.ProductsUpload;
import com.ruoyi.project.module.productsUpload.service.IProductsUploadService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 商品批量上传 信息操作处理
 * 
 * @author lcx
 * @date 2018-08-25
 */
@Controller
@RequestMapping("/module/productsUpload")
public class ProductsUploadController extends BaseController
{
    private String prefix = "module/productsUpload";
	
	@Autowired
	private IProductsUploadService productsUploadService;
	
	@RequiresPermissions("module:productsUpload:view")
	@GetMapping()
	public String productsUpload()
	{
	    return prefix + "/productsUpload";
	}
	
	/**
	 * 查询商品批量上传列表
	 */
	@RequiresPermissions("module:productsUpload:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ProductsUpload productsUpload)
	{
		startPageChange();
		productsUpload.setCompanyId(UserUtils.getDepId());
		List<ProductsUpload> list = productsUploadService.selectProductsUploadList(productsUpload);
		return getDataTable(list);
	}
	
	/**
	 * 新增商品批量上传
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存商品批量上传
	 */
	@RequiresPermissions("module:productsUpload:add")
	@Log(title = "商品批量上传", action = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ProductsUpload productsUpload)
	{		
		return toAjax(productsUploadService.insertProductsUpload(productsUpload));
	}

	/**
	 * 修改商品批量上传
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		ProductsUpload productsUpload = productsUploadService.selectProductsUploadById(id);
		mmap.put("productsUpload", productsUpload);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存商品批量上传
	 */
	@RequiresPermissions("module:productsUpload:edit")
	@Log(title = "商品批量上传", action = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ProductsUpload productsUpload)
	{		
		return toAjax(productsUploadService.updateProductsUpload(productsUpload));
	}
	
	/**
	 * 删除商品批量上传
	 */
	@RequiresPermissions("module:productsUpload:remove")
	@Log(title = "商品批量上传", action = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(productsUploadService.deleteProductsUploadByIds(ids));
	}
	
}
